const book = E = {
	page(_pageNo, _pageSize, name, state) {
		let _tbody = $('#_tbody');
		$.ajax({
			url: url.path + 'wei/list',
			type: 'get',
			data: {
				pageNo: _pageNo,
				pageSize: _pageSize,
				wname: name,
				state: state
			},
			dataType: 'json',
			success: function(res) {
				console.log(res);
				if (res.code == 200) {
					_tbody.empty(); // 将容器清空
					let list = res.data.dataList;

					$('#p_no').html('').html(res.data.pageNo);
					$('#p_count').html('').html(res.data.totalPageCount);
					$('#zong').html('').html(res.data.totalCount);

					$(list).each(function(i, e) {
						let state;
						if (e.state == 0) {
							state = '启用';
						} else if (e.state == 1) {
							state = '禁用';
						} else if (e.state == 2) {
							state = '待审核';
						}
						let _tr = $(`<tr></tr>`)
						let _tds = $(`
									<td>` + e.wid + `</td>
	                                <td>` + e.account + `</td>
									<td>` + e.wname + `</td>
									<td>` + e.wphone + `</td>
									<td>` + state + `</td>
	                        `)
						let _cz = $('<td></td>');

						let _del = $(
							'<button type="button" class="btn btn-danger btn-xs" style="margin-right:10px">审批</button>'
						);
						_cz.append(_del);
						_tr.append(_tds).append(_cz);
						_tbody.append(_tr);

						_del.click(function() {
							$('#myModal').modal('show');
							$('#shenhewid').val(e.wid)
						})

					});
				}
			}
		});
	},
	edit(id, state) {

		if (id != '') {
			$.ajax({
				url: url.path + 'wei/edit',
				data: {
					wid: id,
					state: state
				},
				type: 'POST',
				dataType: 'json',
				success: function(res) {
					if (res.code == 200) {

						window.location.reload();
					}
				},
				error: function() {
					console.log("失败")
				}
			})
		}

	},
	first() {
		let _wname = $('#wname').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _wname, _state);
	},
	tiao() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _wname, _state);
	},
	last() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		let _p_count = $('#p_count').html();
		E.page(_p_count, _size, _wname, _state);
	},
	prev() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		let _pageNo = $('#p_no').html();
		if (_pageNo > 1) {
			_pageNo--;
			E.page(_pageNo, _size, _wname, _state);
		} else {
			alert('已经是第一页了')
		}

	},
	next() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		let _pageNo = $('#p_no').html();
		let _p_count = $('#p_count').html();
		if (_pageNo < _p_count * 1) {
			_pageNo++;
			E.page(_pageNo, _size, _wname, _state);
		} else {
			alert('已经是最后一页了')
		}
	}
}
$(function() {
	E.page(1, 10, '', '');

	$('#chooseSize').change(function() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _size = $(this).val();
		E.page(1, _size, _wname, _state);
	})

	$('#first').click(function() {
		E.first();
	})

	$('#last').click(function() {
		E.last();
	})

	$('#toPno').blur(function() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _pageNo = $('#toPno').val();
		let _pageSize = $('#chooseSize').val();
		let _p_count = $('#p_count').html();
		if (_pageNo <= _p_count * 1) {
			E.page(1, _size, _wname, _state);
		} else {
			alert('不能大于总页数')
		}

	})

	$('#x').click(function() {

		let _wname = $('#wname').val();

		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _wname, _state);
	})

	$('#btn_search').click(function() {
		let _data = $('#name').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _data);
	})

	$('#prev').click(function() {
		E.prev();
	})

	$('#next').click(function() {
		E.next();
	})

	$('#ti').click(function() {
		let id = $('#shenhewid').val();
		let state = $('#shenhestate').val();
		E.edit(id, state);
	})

})